<template>
  <div class="container">
    <h2>文章管理</h2>
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal">
      <el-menu-item 
        class="menu-item" 
        v-for="(route, index) in routerList" 
        :key="index" 
        :index="index.toString()">
        <router-link :to="route.to" class="my_link">{{route.name}}</router-link>
      </el-menu-item>
    </el-menu>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      routerList: [
        {name: "文章中心", to: '/dashboard/article/center'},
        {name: "添加文章", to: '/dashboard/article/add'},
      ],
    }
  },
  mounted() {
  },
  computed: {
    activeIndex() {
      let path = this.$route.path;
      for (let i = 0; i < this.routerList.length; i++) {
        if (path.indexOf(this.routerList[i].to) !== -1) {
          return i.toString()
        }
      }
      return "0"
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  .el-menu-demo {
    margin-top: 20px;
    margin-bottom: 20px;
    .menu-item {
      padding: 0;
    }
  }
  .my_link {
    display:inline-block;
    padding: 0 20px;
  }
}
</style>